/*
 * 创建日期 2009-3-13
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.tag;

import  org.fantasy.common.grid.bean.ReportParam;
import  org.fantasy.common.grid.bean.ReportTagParam;
import  org.fantasy.common.grid.bean.Toolbar;
import  org.fantasy.common.grid.part.Part;
import  org.fantasy.common.grid.part.PartFactory;
import  org.fantasy.common.grid.report.ReportBuilder;
import  org.fantasy.common.grid.report.ReportBuilderFactory;
import  org.fantasy.common.util.Debug;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *  报表统计标签
 * @author: 王文成
 * @version: 1.0
 * @since 2009-3-13
 */
public class ReportStatTag extends AbstractReportTag{
    
    private static final Log log = LogFactory.getLog(ReportStatTag.class);
    
    @Override
    protected String getReportType() {
        return ReportTagParam.REPORT_TYPE_STAT;
    }
    
    public ReportStatTag(){
        log.debug(">>>>>>>>>>>>>>>>>>> New ReportStatTag instance!");
    }
    
    /**
     * 构造表格
     * 
     * @return
     */
    @Override
    protected String getReportHtml() throws Exception {
        Debug debug = new Debug("Report");
        debug.start("Building Report");
        ReportParam param = getReportParam();
        Toolbar bar = param.getToolbar();
        ReportBuilder builder = ReportBuilderFactory.getReportStatBuilder(param);
        Part part = PartFactory.getReportStatPart(param,getRequest());
        StringBuffer html = new StringBuffer(1024);
        html.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + getCtx() + "/theme/report.css\">\n");
        html.append("<table id=\""
                        + param.getId()
                        + "\" style='" + param.getStyle() + ";table-layout:fixed;' cellspacing='0' cellpadding='0' border='0'> \n");
        if( bar.isVisible() ){
            html.append("<tr> \n");
            html.append("	<td height=\"30\"> \n");
            html.append(    part.getToolBar());
            html.append("	</td> \n");
            html.append("</tr> \n");
        }
        html.append("<tr> \n");
        html.append("  <td> \n");
        html.append("	<div class='report'> \n");
        html.append(builder.getReport());
        html.append("	</div> \n");
        html.append("	</td> \n");
        html.append("</tr> \n");
        html.append(part.getPager());
        html.append("</table> \n");
        html.append(part.getScript());
        html.append(part.getParams());
        debug.end("Building Report");
        log.info(debug);
        return html.toString();
    }
}
